package com.ge.modules.api.secondController;

import com.ge.common.annotation.LoginStoreApi;
import com.ge.common.utils.PageUtils;
import com.ge.common.utils.Query;
import com.ge.common.utils.R;
import com.ge.modules.api.service.TbCommissionExtractinfoService;
import com.ge.modules.entity.TbCommissionExtractinfoEntity;
import com.ge.modules.entity.TbStoreEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;
import java.util.Date;
import java.util.List;
import java.util.Map;


/**
 * 佣金提现明细
 *
 * @author lanyonglin
 * @email www.baidu.com
 * @date 2018-04-11 17:29:06
 */
@RestController
@RequestMapping("/api/store/extractinfo")
public class TbStoreCommissionExtractinfoController {
    @Autowired
    private TbCommissionExtractinfoService tbCommissionExtractinfoService;

    /**
     * 查询我的提现列表
     *
     * @param tbStoreEntity
     * @param params
     * @return
     */
    @GetMapping("/list")
    public R list(@LoginStoreApi TbStoreEntity tbStoreEntity, @RequestParam Map<String, Object> params) {
        params.put("userId", tbStoreEntity.getStoreId());
        params.put("userType", tbStoreEntity.getUserType());
        //查询列表数据
        Query query = new Query(params);
        List<TbCommissionExtractinfoEntity> tbCommissionExtractinfoEntityList = tbCommissionExtractinfoService.queryList(query);
        int total = tbCommissionExtractinfoService.queryTotal(query);
        PageUtils pageUtil = new PageUtils(tbCommissionExtractinfoEntityList, total, query.getLimit(), query.getPage());
        return R.ok().put("data", pageUtil);
    }

    /**
     * 信息
     *
     * @param id
     * @return
     */
    @GetMapping("/info/{id}")
    public R info(@PathVariable("id") Integer id) {
        TbCommissionExtractinfoEntity tbCommissionExtractinfoEntity = tbCommissionExtractinfoService.queryObject(id);
        return R.ok().put("data", tbCommissionExtractinfoEntity);
    }

    /**
     * 添加提现申请
     *
     * @param tbStoreEntity
     * @param money
     * @param bankCard 银行卡
     * @param accountName 账户名称
     * @return
     */
    @GetMapping("/getMoney")
    public R getMoney(@LoginStoreApi TbStoreEntity tbStoreEntity, BigDecimal money,String bankCard,String accountName) {
        TbCommissionExtractinfoEntity tbCommissionExtractinfoEntity = new TbCommissionExtractinfoEntity();
        tbCommissionExtractinfoEntity.setExtractinfoMoney(money);
        tbCommissionExtractinfoEntity.setUserType(tbStoreEntity.getUserType());
        tbCommissionExtractinfoEntity.setUpdateTime(new Date());
        tbCommissionExtractinfoEntity.setStatus(0);
        tbCommissionExtractinfoEntity.setCreateTime(new Date());
        tbCommissionExtractinfoEntity.setExtractinfoDescribe("用户 " + tbStoreEntity.getStoreName() + " 申请了提现 金额：" + money);
        tbCommissionExtractinfoEntity.setUserId(tbStoreEntity.getStoreId());
        tbCommissionExtractinfoEntity.setBankCard(bankCard);
        tbCommissionExtractinfoEntity.setAccountName(accountName);
        tbCommissionExtractinfoService.save(tbCommissionExtractinfoEntity);
        return R.ok("提现成功");
    }

}
